package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.MallIncome;
import com.sc.nft.entity.dto.MallIncomeQueryDTO;
import com.sc.nft.entity.dto.MallIncomeQueryPageDTO;
import com.sc.nft.entity.vo.MallIncomeVO;
import com.sc.nft.mapper.MallIncomeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * ip商城收益模板(MallIncome)表Dao层
 *
 * @author wwc
 * @since 2023-05-15 10:50:57
 */
@Slf4j
@Repository
public class MallIncomeDao extends ServiceImpl<MallIncomeMapper, MallIncome> {

    /**
     * 判断当前daoId是否已经存在
     *
     * @param id
     * @return
     */
    public Boolean isExistDaoId(Long id) {
        LambdaQueryWrapper<MallIncome> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MallIncome::getDaoId, id);
        return this.count(queryWrapper) > 0;
    }

    public Page<MallIncomeVO> queryPage(MallIncomeQueryPageDTO mallIncomeQueryPageDTO) {
        Page<MallIncomeVO> page = baseMapper.queryPage(mallIncomeQueryPageDTO.toMp(),mallIncomeQueryPageDTO);
        return page;
    }

    public MallIncomeVO getByIdLeftJoin(Long id) {
        return baseMapper.getByIdLeftJoin(id);
    }

    public List<MallIncomeVO> getQuery(MallIncomeQueryDTO mallIncomeQueryDTO) {
        return baseMapper.getQuery(mallIncomeQueryDTO);
    }

    public List<MallIncome> getIncomeListByDaoId(Long daoId) {
        LambdaQueryWrapper<MallIncome> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallIncome::getDaoId, daoId);
        return this.list(wrapper);
    }
}
